<!DOCTYPE HTML>
<html>
<head>
    <include file="Common:header_include"/>
    <style>
        table td{
            border: 1px solid #ddd;
            text-align: center;
            padding:10px 0;
        }
        table tr:first-child td{
            font-weight: bold;
        }
    </style>
</head>
<body>
<div class="pd-20">
          <table>
               <tr >
                       <td>名称</td>
                       <td>参考值</td>
                       <td>附加值</td>
                       <td>边界值</td>
                       <td>危险值</td>
                       <td>设必填项</td>
                       <td>操作</td>
                 </tr>
             <volist name="data" id="v">
                  <tr>
                      <?php $iteminfo = getiteminfo($v['itemid']);?>
                      <td>{$v['Inspectioniteminfo']['name']}{$v['itemid']}</td>
                      <td><input  class="input-text radius size-M"  style="width: 100px" type="text"  id="refvalue{$v['id']}"  <if condition="$v['refvalue']">value="{$v['refvalue']}"<else/>value="{$iteminfo['standard']}"</if>"></td>
                      <td><input  class="input-text radius size-M"   style="width: 100px"  type="text" id="attachvalue{$v['id']}" value="{$v['attachvalue']}"></td>
                      <td><input  class="input-text radius size-M"   style="width: 100px"  type="text" id="boundary_value{$v['id']}"  <if condition="$v['boundary_value']">value="{$v['boundary_value']}"<else/>value="{$iteminfo['boundary_value']}"</if>></td>
                      <td><input  class="input-text radius size-M"   style="width: 100px"  type="text" id="threshold{$v['id']}"  <if condition="$v['threshold']">value="{$v['threshold']}"<else/>value="{$iteminfo['hazardous_value']}"</if>"></td>
                      <td><input <if condition="$v['defaultselect']">class="btn btn-warning radius"<else/>class="btn btn-secondary radius"</if> type="button" onclick="mandatory('{$v.id}','{$v.defaultselect}')"<if condition="$v['defaultselect']  eq false">value="设为必填项"<else/>value="已设为必填项"</if>></td>
                      <td><input <if condition="$v['refvalue']">class="btn btn-danger radius"<else/>class="btn btn-secondary radius"</if> type="button" onclick="entering('{$v.id}')"<if condition="$v['refvalue']">value="修改"<else/>value="录入"</if>></td>
                  </tr>
              </volist>
       </table>
</div>
<include file="Common:footer_include"/>
<script src="__HJS__jquery-2.1.1.js"></script>
<script type="text/javascript" src="__HUI__lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="__HUI__lib/layer/2.1/extend/layer.ext.js"></script>
<script>
    function entering($id){
        var jqeryobj = new Object();
            jqeryobj.id           =   $id;
            jqeryobj.refvalue     =   $("#refvalue"+$id).val();
            jqeryobj.attachvalue  =   $("#attachvalue"+$id).val();
            jqeryobj.threshold  =   $("#threshold"+$id).val();
            jqeryobj.boundary_value  =   $("#boundary_value"+$id).val();
        var ajaxurl="{:U('Inspectiondetailinfo/edit')}";
        $.ajax({
            url:ajaxurl ,
            type: 'post',
            data:jqeryobj,
            async: true,
            enctype: 'multipart/form-data',
            success: function (data) {
                if(data.status==1){
                    layer.msg('录入成功', {
                        icon: 1,
                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        window.location.reload();
                    });

                }else{
                    layer.msg('录入失败', {icon: 5});
                }

            }
        });
    }
    /**
     * ajax 设定值为必填项
     * @param $id
     * @param $defaultselect
     */
    function mandatory($id,$defaultselect){
        var jqeryobj = new Object();
        if($defaultselect==0){
            $defaultselect=1;
        }else{
            $defaultselect=0;
        }
        jqeryobj.id           =   $id;
        jqeryobj.defaultselect     =   $defaultselect;
        var ajaxurl="{:U('Inspectiondetailinfo/defaultselect')}";
        $.ajax({
            url:ajaxurl ,
            type: 'post',
            data:jqeryobj,
            async: true,
            enctype: 'multipart/form-data',
            success: function (data) {
                if(data.status==1){
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        window.location.reload();
                    });

                }else{
                    layer.msg(data.msg, {icon: 5});
                }

            }
        });
    }

</script>
</body>
</html>